<template>
	<view>
		<view class="nav-back">
			<top-heigth back-title="评价"></top-heigth>
		</view>
		<view class="content-box m-b16 m-t24" v-if="detailList">
			<view class="public-box" style="padding-bottom: 0;padding-top: 0; overflow: hidden;">

				<view class="goods-box">
					<view class="goods">
						<view class="img-box">
							<image class="img" :src="detailList.tAppServiceVo.serviceImage != ''?detailList.tAppServiceVo.serviceImage :''  " mode="widthFix"></image>
						</view>
						<view class="goods-font">
							<view class="start-top">
								<h1 class="goods-h1 start-h1">{{detailList.tAppServiceVo.serviceName}}</h1>
							</view>
							<view class="sale">预约时间：{{detailList.serviceReservedTime}}</view>
						</view>
					</view>
				</view>
				
				<view class="detail-font">
					<view class="left">服务人员</view>
					<view class="right js-font">
						<view class="js-font-left">
							<image :src="detailList.tAppStaffVo.staffCover" mode="widthFix"></image>
						</view>
						<view class="js-font-right">技师：{{detailList.tAppStaffVo.staffName}}</view>
					</view>
				</view>
				<view class="detail-font">
					<view class="left">服务评分</view>
					<view class="right">
						<uv-rate v-model="score" active-color="#FA3534" inactive-color="#b2b2b2" readonly></uv-rate>
					</view>
				</view>
				
				
				<h1 class="order-h1 m-t24">评价内容</h1>
				<uv-textarea v-model="comment" disabled placeholder="请对本次服务做出如实评价！" style="background-color: #F8F8F8;border: none;"></uv-textarea>
				
				<view class="detail-font m-t24">
					<view class="left">上传图片</view>
					<view class="right js-font">
						
					</view>
				</view>
			<view style="width: 100%;">
					<uv-album :urls="urls" multipleSize="138rpx" space="8rpx"></uv-album>
				</view>
				
				
			</view>
		</view>
	</view>
</template>

<script>
	import { checkLogin } from "@/util/checkLogin.js"
	
	import TopHeigth from '@/components/TopHeigth.vue'
	import config from '@/common/config'
	export default {
		data() {
			return {
				fileList1:[],
				detailList: null,
				comment:'',
				score:'',
				id:'',
				aaa1: ["https://img-home.csdnimg.cn/images/20201124032511.png"],
				imageBanner:'',
				urls:[]
			}
		},
		components: { TopHeigth },
		onLoad(e) {
			this.id = e.id
			this.getOrder()
		},
		methods: {
			deletePic2(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead2(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`aaa${event.name}`].length
				lists.map((item) => {
					this[`aaa${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise2(lists[i].url)
					let item = this[`aaa${event.name}`][fileListLen]
					this[`aaa${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise2(url) {
				var _this = this;
				return new Promise((resolve, reject) => {
					
					let a = uni.uploadFile({
						url: config.baseUrl + "/api/system/loginController/uploadImage?accessKey=buma_admin&sign=e97ece2e8fc18f588ddae8f31a30d972", // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							console.log('11111111')
							if(_this.imageBanner==""){
								_this.imageBanner = _this.imageBanner+JSON.parse(res.data).data
							}else{
								_this.imageBanner = _this.imageBanner+","+JSON.parse(res.data).data
							}
							
							resolve(res.data.data)
						}
					});
				})
			},
			getOrder() {
				uni.$u.http.post('/api/shop/v1_0/tAppOrderRCA/turnTAppOrderInfo',{
						id:this.id,
				}).then((res) => {
					this.detailList = res.data
					checkLogin((userinfo) => {
						uni.$u.http.post('/api/shop/v1_0/tAppUserCommentRCA/turnTAppUserCommentInfo',{
								orderCode:res.data.orderCode,
								appUserId: userinfo.id
						}).then((res) => {
							this.score = res.data.score
							this.comment = res.data.comment
							this.urls = res.data.commentImg.split(",")
							console.log(this.urls)
							// this.aaa1 = res.data.commentImg.split(",")
						})
					})
					
				})
				
			},
			
			upAssess() {
				if(this.score == ''){
					return uni.showToast({
						title: '评分不能为空',
						icon: 'none'
					});
				}
				uni.$u.http.post('/api/shop/v1_0/tAppUserCommentRCA/insertTAppUserComment',{
						appUserId:this.id,
						orderCode:this.detailList.orderCode,
						staffId:this.detailList.staffId,
						supplierId:this.detailList.supplierId,
						
						score:this.score,
						userName:this.detailList.userName,
						userMobile:this.detailList.userMobile,
						comment:this.comment,
						commentImg:this.imageBanner,
						
				}).then((res) => {
					this.goOrder()
				}) 
			},
			goOrder(){
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="scss" scoped>
	@mixin flex($direction: row) {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: $direction;
	}
	.uv-nav-slot {
		@include flex;
		align-items: center;
		justify-content: space-between;
		border-width: 0.5px;
		border-radius: 100px;
		border-color: #dadbde;
		padding: 3px 7px;
		opacity: 0.8;
	}
	
	
	.complaint-top{
		@include flex;
		align-items: center;
		justify-content:space-between;
		.complaint-top-img{
			@include flex;
			align-items: center;
			justify-content:flex-start;
			font-size: 26rpx;
			.img{
				border-radius: 40rpx;
				overflow: hidden;
				font-weight: bold;
				color: #333;
				margin-right: 16rpx;
				image{
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
		.complaint-top-r{
			font-size: 24rpx;
			color: #999;
		}
	}
	.goods-bottom{
		@include flex;
		align-items: center;
		justify-content:space-between;
		.goods-bottom-r{
			@include flex;
			align-items: center;
			justify-content:space-between;
		}
		.goods-bottom-but{
			width: 136rpx;
			height: 56rpx;
			line-height: 56rpx;
			font-size: 24rpx;
			color: #333;
			border: 2rpx solid #CBCBCB;
			border-radius:56rpx;
			text-align: center;
			margin-left: 16rpx;
		}
	}
	.detail-font{
		@include flex;
		align-items: center;
		justify-content:flex-start;
		font-size: 26rpx;
		margin-bottom: 32rpx;
		
		.left{
			width:120rpx;
			color: #333333;
			font-weight: bold;
		}
		.right{
			color: #333;
		}
	}
	.js-font{
		@include flex;
		align-items: center;
		justify-content:flex-start;
		font-size: 24rpx;
		.js-font-left{
			width: 40rpx;
			height: 40rpx;
			border-radius: 40rpx;
			overflow: hidden;
			margin-right: 6rpx;
			image{
				width: 40rpx;
				
			}
		}
		.js-font-rigth{
			color: #333;
		}
	}
	
	
	
	/* 公共复制过来的 */
	/* 商品 */
	.goods-box{
		.goods{
			display: flex;
			align-items: center;
			justify-content: flex-start;
			padding:32rpx 0;
			border-bottom: 2rpx solid #EEEEEE;
			.img-box{
				width:160rpx;
				height: 160rpx;
				border-radius:20rpx;
				margin-right: 24rpx;
				background:#f8f8f8;
				overflow: hidden;
				display: flex;
				align-items: center;
				.img{
					width: 160rpx;
					height: 160rpx;
				}
			}
			
			.goods-font{
				width:calc(100% - 184rpx);
				.goods-h1{
					font-size:30rpx;
					font-weight: bold;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
					margin-bottom: 8rpx;
				}
				.sale{
					font-size: 24rpx;
					color: #999;
					margin-bottom: 24rpx;
				}
				.font-bottom{
					display: flex;
					align-items: flex-end;
					justify-content:space-between;
					.font-bottom-l{
						display: flex;
						align-items: flex-end;
						justify-content: flex-start;
						.goods-span-red{
							font-size: 24rpx;
						}
						.red{
							color: #F82727;
							font-size: 34rpx;
							font-weight: bold;
							margin-right: 16rpx;
							span{
								
							}
						}
						.grey{
							color: #999;
							font-size: 24rpx;
						}
						.grey2{
							color: #999;
							font-size: 24rpx;
							text-decoration:line-through;
						}
					}
				}
			}
		}
		.goods:last-child{
			border-bottom: none;
		}
	}
	
	
</style>
